package com.mark.spring.annotation.auto.assembly.autowired;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @Description:
 * @Author: Mark
 * @CreateDate: 2019/9/22 22:48
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 */
@ComponentScan(basePackages = {"com.mark.spring.annotation.auto.assembly.autowired"})
public class AutowiredBootstrap {

    public static void main(String[] args) {
        //加载配置，获取bean
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AutowiredBootstrap.class);
        BookService bookService = applicationContext.getBean(BookService.class);

        System.out.println("Service 层注入的BookDao实例："+bookService.bookDao);

        BookDao bookDao = applicationContext.getBean(BookDao.class);
        System.out.println("容器中的BookDao实例："+bookDao);

        //结果：通过比较两者的hashcode发现两者是同一个实例
    }
}
